/**
 * Classe permettant l'affichage de l'ensemble des ascenseurs
 * @authors: Bertrand GUILLAUMOND, Victor BRENET
 * @version 1.0
 */


import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class Gui extends JFrame implements ActionListener, WindowListener{
		
	Color c;
	private JPanel panel;
	private JPanel draw;
	private ElevatorPanel[] elevatorPanels;
	private JButton statistics;
	private StatisticsFrame statFrame;

	public Gui(ElevatorPanel[] ep){
		
		setTitle("Suivi des ascenseurs");
		setSize(480,800);
		setLayout(new BorderLayout(1,2));
	 	panel = new JPanel();
		panel.setBackground(Color.white);
		elevatorPanels = ep;

		getContentPane().add(BorderLayout.NORTH, panel);
		
		draw = new JPanel();
		draw.setBackground(new Color(102,102,102));
		draw.setLayout(new GridLayout(1,6));

		for(int i = 0; i < 6; i++)
		{
			draw.add(elevatorPanels[i]);
			elevatorPanels[i].repaint();
		}

		getContentPane().add(BorderLayout.CENTER, draw);
		addButtons();
		addListeners();
		setVisible(true);
	}

	public ElevatorPanel[] getPanels()
	{
		return elevatorPanels;
	}
	
	public void addButtons()
	{
		statistics = new JButton("Afficher les statistiques");
		panel.add(statistics);
	}
	
	public void addListeners()
	{
		statistics.addActionListener(this);
		addWindowListener(this);
	}


	public void actionPerformed(ActionEvent ev)
	{
		Statistics[] stats = new Statistics[6];
		
		for(int i = 0; i < 6; i++)
		{
			stats[i] = elevatorPanels[i].getElevator().getStatistics();
		}
		statFrame = new StatisticsFrame(stats);
	}

	public void windowClosing(WindowEvent e) {
		add(new Label("fini dans 5 secondes !"));
		pack();
		
		setVisible(false);
		dispose(); 
		System.exit(0); 
  	}
 	public void windowOpened(WindowEvent e) {}
  	public void windowActivated(WindowEvent e) {}
  	public void windowDeactivated(WindowEvent e) {}
 	public void windowClosed(WindowEvent e) {}
  	public void windowIconified(WindowEvent e) {}
 	public void windowDeiconified(WindowEvent e) {}
	
	public void refresh()
	{
		for(int i = 0; i < 6; i++)
		{
			elevatorPanels[i].repaint();
		}
	}
}
